<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets">

<h:head>
	<title>Dodaj/edytuj lekarza</title>
</h:head>
<body>
	<ui:composition template="/pages/common/commonLayout.xhtml">
		<ui:define name="content">
			<h:form>
		<h:messages errorStyle="color: purple;" />
		<p:panel>
				<table>
					<tr>
						<td colspan="5"><b><h:outputText value="Dane lekarza:" /></b>
						</td>
					</tr>
					<tr>
						<td><h:outputLabel for="firstName" value="Imie:" /></td>
						<td><p:inputText id="firstName"
								value="#{doctorMB.doctor.firstName}" required="true">
								<f:validateLength minimum="2" maximum="20" />
								<f:validateRegex pattern="[a-zA-Z]*" />
							</p:inputText></td>
						<td width="50px" />
						<td><h:outputLabel for="middleName" value="Drugie imie:" /></td>
						<td><p:inputText id="middleName" required="false"
								value="#{doctorMB.doctor.middleName}">
								<f:validateLength minimum="2" maximum="20" />
								<f:validateRegex pattern="[a-zA-Z]*" />
							</p:inputText></td>
					</tr>
					<tr>
						<td><h:outputLabel for="secondName" value="Nazwisko:" /></td>
						<td><p:inputText id="secondName" required="true"
								value="#{doctorMB.doctor.lastName}">
								<f:validateLength minimum="2" maximum="20" />
								<f:validateRegex pattern="[a-zA-Z]*" />
							</p:inputText></td>
						<td width="50px" />
						<td><h:outputLabel for="pesel" value="Pesel:" /></td>
						<td><p:inputText id="pesel" value="#{doctorMB.doctor.pesel}"
								required="true">
								<f:validateRegex pattern="[0-9]{11}" />
								<f:validator validatorId="peselValidator" />
							</p:inputText></td>
					</tr>
					<tr>
						<td><h:outputLabel for="nip" value="Nip:" /></td>
						<td><p:inputText id="nip" value="#{doctorMB.doctor.nip}">
								<f:validateRegex pattern="[0-9]{10}" />
								<f:validator validatorId="nipValidator" />
							</p:inputText></td>
						<td width="50px" />
						<td><h:outputLabel for="phone" value="Telefon:" /></td>
						<td><p:inputText id="phone" required="true"
								value="#{doctorMB.doctor.mobilePhone}">
								<f:validateLength minimum="9" maximum="12" />
								<f:validateRegex pattern="[0-9]*" />
							</p:inputText></td>
					</tr>
					<tr>
						<td><h:outputLabel for="email" value="Email:" /></td>
						<td><p:inputText id="email" value="#{doctorMB.doctor.email}" required="false" > 
								<f:validator validatorId="emailValidator" />
							</p:inputText></td>
						<td width="50px" />
						<td><h:outputLabel for="gender" value="Plec:" /></td>
						<td><p:selectOneMenu id="gender"
								value="#{doctorMB.doctor.gender}" required="true">
								<f:selectItems value="#{enumBean.genderValues}" var="gender"
									itemValue="#{gender}" itemLabel="#{gender.label}" />
							</p:selectOneMenu></td>
					</tr>
					<tr>
						<td><h:outputLabel for="birthDate" value="Data urodzenia:" /></td>
						<td><p:calendar id="birthDate" required="true" locale="pl" navigator="true"
								value="#{doctorMB.doctor.birthDate}" effect="fold" yearRange="c-70:c+1" /></td>
						<td width="50px" />
						<td><h:outputLabel for="spec" value="Specjalizacja:" /></td>
						<td><p:selectOneMenu id="spec"
								value="#{doctorMB.doctor.spec}" required="true">
								<f:selectItems value="#{enumBean.specializationValues}"
									var="spec" itemValue="#{spec}" itemLabel="#{spec.label}" />
							</p:selectOneMenu></td>
					</tr>
					<tr>
						<td><h:outputLabel for="czasWizyty" value="Czas trwania wizyty:" /></td>
						<td>
						<p:selectOneMenu id="czasWizyty" required="true" 
							value="#{doctorMB.doctor.visit}" converter="javax.faces.Integer">
							<f:selectItem itemValue="10" itemLabel="10"/>
							<f:selectItem itemValue="15" itemLabel="15"/>
							<f:selectItem itemValue="20" itemLabel="20"/>
							<f:selectItem itemValue="30" itemLabel="30"/>
						</p:selectOneMenu>
						</td>
					</tr>
					<tr height="20px" />
					<tr>
						<td colspan="5"><b><h:outputText value="Adres:" /></b></td>
					</tr>
					<tr>
						<td><h:outputLabel for="street" value="Ulica:" /></td>
						<td><p:inputText id="street"
								value="#{doctorMB.doctor.address.street}" required="true" /></td>
						<td width="50px" />
						<td><h:outputLabel for="streetNumber" value="Numer:" /></td>
						<td><p:inputText id="streetNumber" required="true"
								value="#{doctorMB.doctor.address.streetNumber}" /></td>
					</tr>
					<tr>
						<td><h:outputLabel for="flatNo" value="Mieszkanie:" /></td>
						<td><p:inputText id="flatNo"
								value="#{doctorMB.doctor.address.flatNumber}" required="false" /></td>
						<td width="50px" />
						<td><h:outputLabel for="postal" value="Kod pocztowy:" /></td>
						<td><p:inputText id="postal" required="true"
								value="#{doctorMB.doctor.address.postalCode}">
								<f:validateLength minimum="5" maximum="6" />
								<f:validateRegex pattern="[0-9]{2}-?[0-9]{3}" />
							</p:inputText></td>
					</tr>
					<tr>
						<td><h:outputLabel for="postalTown" value="Poczta:" /></td>
						<td><p:inputText id="postalTown" required="true"
								value="#{doctorMB.doctor.address.postalTown}">
								<f:validateLength minimum="2" maximum="20" />
							</p:inputText></td>
					</tr>
					</table>
					</p:panel>
					<p:panel id="table">
					<table>
						<tr>
							<td><h:outputLabel for="user" value="Powiazany użytkownik:" /></td>
							<td><p:selectOneMenu id="user" converter="userConverter" disabled="#{doctorMB.forMe}"
									value="#{doctorMB.doctor.user}" required="false">
									<f:selectItems value="#{doctorMB.otherDoctorUsers}" />
								</p:selectOneMenu></td>
							<td><h:outputLabel id="toMe" value="Przypisz do mnie" /></td>
							<td><p:selectBooleanCheckbox value="#{doctorMB.forMe}">
								<p:ajax event="change" update="table" />
							</p:selectBooleanCheckbox></td> 
					</tr>
					<tr>
						<td /><td />
						<td /><td />
						<td align="right"><p:commandButton id="reset" value="Wyczysc"
								action="#{doctorMB.reset}" ajax="false" /> <p:commandButton
								id="submit" value="Zapisz" action="#{doctorMB.save}"
								ajax="false" /></td>
					</tr>
				</table>
			</p:panel>
			</h:form>
		</ui:define>
	</ui:composition>
</body>
</html>
